<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="/js/jquery.js"></script>
    <link rel="stylesheet" href="/css/element-ui@2.13.2.index.css">
    <script src="/js/vue.min.js"></script>
    <script src="/js/vue-resource.min.js"></script>
    <script src="/js/index.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/axios.min.js"></script>
    <!-- 字体图标css的引入 -->
    <link rel="stylesheet" href="/css/font_830376_qzecyukz0s.css">
    <link rel="stylesheet" href="/css/color-dark.css">
    <link rel="stylesheet" href="/css/icon.css">
    <link rel="stylesheet" href="/css/reset.css">
    <link rel="stylesheet" href="/css/base.css">
    <title></title>
</head>

<body>
<div id="manage">
    <!-- 头部 -->
    <div class="wrapper">
        <!-- 头部 -->
        <div class="header">
            <!-- 折叠按钮 -->
            <div class="header-left">
                人脸库管理
            </div>

            <!-- <div class="logo">后台管理系统</div> -->
            <div class="header-right">
                <div class="header-user-con">
                    <!-- 全屏显示 -->
                    <div class="btn-fullscreen" @click="handleFullScreen">
                        <el-tooltip effect="dark" :content="fullscreen?`取消全屏`:`全屏`" placement="bottom">
                            <i class="el-icon-rank"></i>
                        </el-tooltip>
                    </div>
                    <div class="user-avator">
                        <img src="/image/img.jpg" />
                    </div>
                    <!-- 用户名下拉菜单 -->
                    <el-dropdown class="user-name" trigger="click" @command="handleCommand">
                            <span class="el-dropdown-link">
                                {{username}}
                                <i class="el-icon-caret-bottom"></i>
                            </span>
                        <el-dropdown-menu slot="dropdown">
                            <a href="https://github.com/lin-xin/vue-manage-system" target="_blank">
                                <el-dropdown-item>项目仓库</el-dropdown-item>
                            </a>
                            <el-dropdown-item divided command="loginout">退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </div>
            </div>
        </div>

        <!-- 侧边部分 -->
        <div data-v-68d67528="" class="sidebar">
            <ul data-v-68d67528="" role="menubar" class="sidebar-el-menu el-menu side-ul"
                style="background-color: rgb(50, 65, 87);">
                <li data-v-68d67528="" role="menuitem" tabindex="-1" class="el-menu-item"
                    style="padding-left: 20px; color: rgb(191, 203, 217); background-color: rgb(50, 65, 87);"><i
                        data-v-68d67528="" class="el-icon-lx-home"></i><span data-v-68d67528="">首页</span></li>
                <li data-v-68d67528="" role="menuitem" tabindex="-1" class="el-menu-item  is-active"
                    style="padding-left: 20px; color: rgb(191, 203, 217); background-color: rgb(50, 65, 87);"><i
                        data-v-68d67528="" class="el-icon-lx-calendar"></i><span data-v-68d67528="">人脸库管理</span>
                </li>
                <li data-v-68d67528="" role="menuitem" tabindex="-1" class="el-menu-item"
                    style="padding-left: 20px; color: rgb(32, 160, 255); background-color: rgb(50, 65, 87);"><i
                        data-v-68d67528="" class="el-icon-lx-global"></i><span data-v-68d67528="">特征查询</span></li>
            </ul>
        </div>

        <!-- 内容部分 -->
        <div class="content-box">
            <div class="content">
                <div>
                    <div class="crumbs">
                        <el-breadcrumb separator="/">
                            <el-breadcrumb-item>{{title}}</el-breadcrumb-item>
                        </el-breadcrumb>
                    </div>
                    <div class="container">
                        <div>
                            <el-page-header @back="back"></el-page-header>
                        </div>
                        <div class="form-box">
                            <el-form ref="form"
                                     label-width="150px" enctype="multipart/form-data">
                                <el-row type="flex">
                                    <el-col style="flex: 1">
                                        <div style="width: 100%">
                                            <el-row type="flex"  class="row-bg">
                                                <el-col style="flex: 1">
                                                    <el-form-item  label="人脸库名称1" :inline="inline">
                                                        <el-select v-model="sets[0].set_name" style="width: 100%" name="set_name" placeholder="请选择">
                                                            <el-option
                                                                    v-for="item in libraryNames"
                                                                    :key="item.value"
                                                                    :label="item.label"
                                                                    :value="item.value">
                                                            </el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col style="flex: 1">
                                                    <el-form-item label="特征版本号" :inline="inline">
                                                        <el-select v-model="sets[0].model_version" style="width: 100%" name="model_version" placeholder="请选择">
                                                            <el-option
                                                                    v-for="item in model_versionOptions"
                                                                    :key="item.value"
                                                                    :label="item.label"
                                                                    :value="item.value">
                                                            </el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </div>
                                        <div style="width: 100%">
                                            <el-row type="flex" class="row-bg">
                                                <el-col :span="12" style="flex: 1">
                                                    <el-form-item label="展示查询结果的数量">
                                                        <el-input-number v-model="optional.top_n" :min="1" :max="10"></el-input-number>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12" style="flex: 1">
                                                    <el-form-item label="相似度阈值">
                                                        <el-input-number v-model="optional.matched_similar" :min="0.01" :max="1" :step="0.01"></el-input-number>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </div>

                                    </el-col>
                                    <el-col>
                                        <el-form-item label="人员图片">
                                            <div class="form-group">
                                                <i class="el-icon-plus"></i>
                                                <div class="group-upload">
                                                    <input ref="file" id="file" type="file" name="file" @change="fileOnchange(this)" accept="image/jpeg, image/png">
                                                    <img id="img" ref="img" style="width: 120px; height: 120px;">
                                                </div>
                                            </div>
                                        </el-form-item>
                                    </el-col>
                                    <el-col >
                                        <el-button type="primary" @click="onSubmit">{{btnText}}</el-button>
                                    </el-col>
                                </el-row>



<!--                                <el-row type="flex" class="row-bg">-->
<!--                                    <el-col :span="7">-->
<!--                                        <el-row type="flex" class="row-bg">-->
<!--                                            <el-col>-->
<!--                                                <el-form-item  label="人脸库名称" :inline="inline">-->
<!--                                                    <el-select v-model="sets[0].set_name" name="set_name" placeholder="请选择">-->
<!--                                                        <el-option-->
<!--                                                                v-for="item in libraryNames"-->
<!--                                                                :key="item.value"-->
<!--                                                                :label="item.label"-->
<!--                                                                :value="item.value">-->
<!--                                                        </el-option>-->
<!--                                                    </el-select>-->
<!--                                                </el-form-item>-->
<!--                                            </el-col>-->
<!--                                            <el-col :span="7">-->
<!--                                                <el-form-item label="特征版本号" :inline="inline">-->
<!--                                                    <el-select v-model="sets[0].model_version" name="model_version" placeholder="请选择">-->
<!--                                                        <el-option-->
<!--                                                                v-for="item in model_versionOptions"-->
<!--                                                                :key="item.value"-->
<!--                                                                :label="item.label"-->
<!--                                                                :value="item.value">-->
<!--                                                        </el-option>-->
<!--                                                    </el-select>-->
<!--                                                </el-form-item>-->
<!--                                            </el-col>-->
<!--                                        </el-row>-->
<!--                                        <el-row type="flex" class="row-bg">-->
<!--                                            <el-col>-->
<!--                                                <el-form-item label="展示查询结果的数量">-->
<!--                                                    <el-input-number v-model="optional.top_n" :min="1" :max="10"></el-input-number>-->
<!--                                                </el-form-item>-->
<!--                                            </el-col>-->
<!--                                            <el-col>-->
<!--                                                <el-form-item label="相似度阈值">-->
<!--                                                    <el-input-number v-model="optional.matched_similar" :min="0.01" :max="1" :step="0.01"></el-input-number>-->
<!--                                                </el-form-item>-->
<!--                                            </el-col>-->
<!--                                        </el-row>-->
<!--                                    </el-col>-->
<!--                                    <el-col :span="7">-->
<!--                                        <el-row type="flex" class="row-bg">-->
<!--                                            <el-col :span="7">-->
<!--                                                <el-form-item label="人员图片">-->
<!--                                                    <div class="form-group">-->
<!--                                                        <i class="el-icon-plus"></i>-->
<!--                                                        <div class="group-upload">-->
<!--                                                            <input ref="file" id="file" type="file" name="file" @change="fileOnchange(this)" accept="image/jpeg, image/png">-->
<!--                                                        </div>-->
<!--                                                        <img id="img" ref="img" style="width: 120px; height: 120px;">-->
<!--                                                    </div>-->
<!--                                                </el-form-item>-->
<!--                                            </el-col>-->
<!--                                            <el-col>-->
<!--                                                <el-form-item>-->
<!--                                                    <el-button type="primary" @click="onSubmit">{{btnText}}</el-button>-->
<!--&lt;!&ndash;                                                    <el-button @click="cancel">取消</el-button>&ndash;&gt;-->
<!--                                                </el-form-item>-->
<!--                                            </el-col>-->
<!--                                        </el-row>-->
<!--                                    </el-col>-->
<!--                                </el-row>-->
                            </el-form>
                        </div>
                        <div>
                            <el-table :data="tableData" border class="table" ref="multipleTable"
                                      header-cell-class-name="table-header">
                                <!-- <el-table-column width="55" align="center"></el-table-column> -->
                                <el-table-column prop="id" label="人员ID"></el-table-column>
                                <el-table-column prop="set_name" label="人脸库名称"></el-table-column>
                                <el-table-column prop="model_version" label="特征版本号"></el-table-column>
                                <el-table-column prop="similar" label="相似度"></el-table-column>
<!--                                <el-table-column prop="ctime" label="创建时间">-->
<!--                                    <template slot-scope="scope">-->
<!--                                        {{timeStampToString(scope.row.ctime)}}-->
<!--                                    </template>-->
<!--                                </el-table-column>-->
                                <el-table-column label="底库图片" align="center">
                                    <template slot-scope="scope">
                                        <el-image
                                                class="table-td-thumb"
                                                :src="scope.row.urls[0]"
                                                :preview-src-list="scope.row.urls[0]"
                                        ></el-image>
                                    </template>
                                </el-table-column>
                                <el-table-column label="操作" width="180" align="center">
                                    <template slot-scope="scope">
                                        <el-button type="text"  size="small" icon="el-icon-info"
                                                   @click="handleDetail(scope.row)">查看详情</el-button>
<!--                                        <el-button type="text"  size="small" icon="el-icon-edit"-->
<!--                                                   @click="handleEdit(scope.row)">编辑</el-button>-->
<!--                                        <el-button type="text"  size="small" icon="el-icon-delete" class="red"-->
<!--                                                   @click="handleDelete(scope.$index, scope.row)">删除</el-button>-->
                                    </template>
                                </el-table-column>
                            </el-table>
                            <div class="pagination">
                                <el-pagination background layout="total, prev, pager, next"
                                               :current-page="query.pageIndex" :page-size="query.pageSize" :total="pageTotal"
                                               @current-change="handlePageChange"></el-pagination>
                            </div>
                        </div>
                    </div>
                </div>
                <div>
                    <!--显示查询结果-->
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    var manage = new Vue({
        el: '#manage',
        data: {
            fullscreen: false,
            title: '特征查询',
            readonly: true,
            btnText: '查询',
            inline: true,
            dialogVisible: false,
            headers: {
                'Authorization': window.localStorage['token']
            },
            libraryNames: [],     // 人脸库名称列表
            sets: [{
                set_name: '',
                model_version: '',
            }],
            optional: {
                top_n: 1,
                matched_similar: 0.3
            },
            file: {},
            // 返回的结果集
            tableData: [],
            pageTotal: 0,
            query: {
                pageIndex: 1,
                pageSize: 10
            },
        },
        watch: {

        },
        computed: {
            username() {
                let username = localStorage.getItem('ms_username');
                return username ? username : this.name;
            }
        },
        mounted() {

        },
        created() {
            this.getLibraryNames();
        },
        methods: {

            // 分页导航
            handlePageChange(val) {
                this.$set(this.query, 'pageIndex', val);
                this.getData();
            },

            // 获取所有的人脸库名称
            // 请求数据
            // 调用自定义axios
            getLibraryNames() {
                axiosGetRequst('/api/library/list', null)
                    .then(result => {
                        if (result.status == 200) {
                            for (let item of result.data.items) {
                                let libraryName = {
                                    value: item.set_name,
                                    label: item.set_name
                                };
                                // 将人脸库名称添加到libraryNames
                                this.libraryNames.push(libraryName);

                            }
                        } else {
                            this.$message.error(result.message);
                        }
                    });
            },

            // 文件改变时
            fileOnchange(e) {
                let files = document.getElementById('file').files;
                let file = files[0];
                let reader = new FileReader();
                reader.onload = () => {
                    this.$refs.img.src = reader.result;
                }
                this.file = file;
                reader.readAsDataURL(file);
            },

            back() {
                window.history.back(-1);
            },

            onSubmit() {
                var form = new FormData();
                form.append('sets[0].set_name', this.sets[0].set_name);
                form.append('sets[0].model_version', this.sets[0].model_version);
                form.append('optional.top_n', this.optional.top_n);
                form.append('optional.matched_similar', this.optional.matched_similar);
                form.append('file', this.file);
                axiosPostFormDataRequest('/api/search', form)
                    .then(result => {
                        if (result.status == 200) {
                            this.tableData = result.data.items;
                            this.$message.success('查询人脸用户成功');
                        } else {
                            this.$message.error(result.message);
                        }
                        this.pageTotal = this.tableData.length;
                    })
            },
            cancel() {
                window.history.back(-1);
            },


            // 查询结果显示
            showResult() {

            },

            // 查看详情
            handleDetail(row) {
                var url = 'personDetail?id=' + row.id
                    + '&setName=' + row.set_name;
                if(row.model_version.length === 0) {
                    url = url + '&modelVersion=null';
                } else {
                    url = url + '&modelVersion=' + row.model_version;
                }
                window.location.href = url;
            },

            // 检查文件是否超出指定的大小
            beforeAvatarUpload(file) {
                const isJPG = file.type === 'image/jpeg' || 'image/png';
                const isLt2M = file.size / 1024 / 1024 < 2;

                if (!isJPG) {
                    this.$message.error('上传头像图片只能是 JPG 格式!');
                }
                if (!isLt2M) {
                    this.$message.error('上传头像图片大小不能超过 2MB!');
                }
                return isJPG && isLt2M;
            },

            // 用户名下拉菜单选择事件
            handleCommand(command) {
                if (command == 'loginout') {
                    localStorage.removeItem('ms_username');
                    window.localStorage["token"] = '';
                    window.location.href = 'login';
                }
            },
            // 全屏事件
            handleFullScreen() {
                let element = document.documentElement;
                if (this.fullscreen) {
                    if (document.exitFullscreen) {
                        document.exitFullscreen();
                    } else if (document.webkitCancelFullScreen) {
                        document.webkitCancelFullScreen();
                    } else if (document.mozCancelFullScreen) {
                        document.mozCancelFullScreen();
                    } else if (document.msExitFullscreen) {
                        document.msExitFullscreen();
                    }
                } else {
                    if (element.requestFullscreen) {
                        element.requestFullscreen();
                    } else if (element.webkitRequestFullScreen) {
                        element.webkitRequestFullScreen();
                    } else if (element.mozRequestFullScreen) {
                        element.mozRequestFullScreen();
                    } else if (element.msRequestFullscreen) {
                        // IE11
                        element.msRequestFullscreen();
                    }
                }
                this.fullscreen = !this.fullscreen;
            },
        }
    })

</script>
</body>

</html>